package com.yumis.service.modules.car.controller;

import com.yumis.service.common.enums.HttpState;
import com.yumis.service.common.vo.Response;
import com.yumis.service.model.pojo.CarBrand;
import com.yumis.service.modules.car.service.CarBrandService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("carbrand")
public class CarBrandController {
    @Autowired
    private CarBrandService carBrandService;

    /**
     * 新增车辆品牌信息
     * @param carBrand
     * @return
     */
    @PostMapping("addCarBrand")
    public ResponseEntity<Response> addCarBrand(@Valid CarBrand carBrand){
        carBrandService.addCarBrand(carBrand);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }

    /**
     * 修改车辆品牌信息
     * @param carBrand
     * @return
     */
    @PostMapping("updateCarBrand")
    public ResponseEntity<Response> updateCarBrand(@Valid CarBrand carBrand){
        carBrandService.updateCarBrand(carBrand);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }

    /**
     * 根据id删除车辆信息
     * @param id
     * @return
     */
    @PostMapping("deleteByIdCarBrand")
    public ResponseEntity<Response> deleteByIdCarBrand(@RequestParam("id")Long id){
        carBrandService.deleteByIdCarBrand(id);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }

    /**
     * 根据id批量删除车辆品牌信息
     * @param ids
     * @return
     */
    @PostMapping("deleteCarBrand")
    public ResponseEntity<Response> deleteCarBrand(@RequestParam("id")Long[] ids){
        carBrandService.deleteCarBrand(ids);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }

    /**
     * 查询所有的车牌号码
     * @param page
     * @param rows
     * @return
     */
    @GetMapping("queryCarBrand")
    public ResponseEntity<Response> queryCarBrand(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                  @RequestParam(value = "rows", defaultValue = "10") Integer rows){
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK,carBrandService.queryCarBrand(page,rows)));
    }
}
